home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / TRIM.ICN < prev    next >
Text File  |  1992-09-28  |  1KB  |  49 lines

  1. ############################################################################
  2. #
  3. #    File:     trim.icn
  4. #
  5. #    Subject:  Program to trim lines in a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program copies lines from standard input to standard out-
  14. #  put, truncating the lines at n characters and removing any trail-
  15. #  ing blanks. The default value for n is 80.  For example,
  16. #  
  17. #          trim 70 <grade.txt >grade.fix
  18. #  
  19. #  copies grade.txt to grade.fix, with lines longer than 70 charac-
  20. #  ters truncated to 70 characters and the trailing blanks removed
  21. #  from all lines.
  22. #  
  23. #     The -f option causes all lines to be n characters long by
  24. #  adding blanks to short lines; otherwise, short lines are left as
  25. #  is.
  26. #
  27. ############################################################################
  28. #
  29. #  Links: options
  30. #
  31. ############################################################################
  32.  
  33. link options
  34.  
  35. procedure main(args)
  36.    local n, pad, line, opts
  37.  
  38.    opts := options(args,"f")
  39.    if \opts["f"] then pad := 1 else pad := 0
  40.    n := (0 <= integer(args[1])) | 80
  41.  
  42.    while line := read() do {
  43.       line := line[1+:n]
  44.       line := trim(line)
  45.       if pad = 1 then line := left(line,n)
  46.       write(line)
  47.       }
  48. end
  49.